package qmsz.api.service.impl;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qmsz.api.dao.QMChargeOrderDetailDAO;
import qmsz.api.domain.QMChargeOrderDetail;
import qmsz.api.service.QMChargeOrderDetailService;

@Service
public class QMChargeOrderDetailServiceImpl implements QMChargeOrderDetailService {
	
	private static final Logger logger = Logger.getLogger(QMChargeOrderDetailServiceImpl.class);

	@Autowired
	private QMChargeOrderDetailDAO qmcodDAO;
	
	@Override
	public QMChargeOrderDetail findChargeOrderDetailByCardNum(String cardNum) {
		QMChargeOrderDetail value = null;
		try {
			value = qmcodDAO.findChargeOrderDetailByCardNum(cardNum);
		} catch (Exception e) {
			logger.error("query error", e);
			value = null;
		}
		return value;
	}
	
	@Override
	public QMChargeOrderDetail findChargeOrderDetailByCardPwd(String cardPwd) {
		QMChargeOrderDetail value = null;
		try {
			value = qmcodDAO.findChargeOrderDetailByCardPwd(cardPwd);
		} catch (Exception e) {
			logger.error("query error", e);
			value = null;
		}
		return value;
	}
	
	@Override
	public boolean markUsed(String cardNo) {
		boolean flag = false;
		try {
			flag = qmcodDAO.updateCODStatusByCardNum(cardNo, 0, 1) == 1;
		} catch (Exception e) {
			logger.error("update error", e);
			flag = false;
		}
		return flag;
	}
}
